import { OnlineTeacherActionType } from '../actions/onlineTeacherAction'

const online_state = {
  teachers: [],
  recordingIds: []
}

const OnlineTeacherState = (state = online_state, action) => {
  switch(action.type) {
    case OnlineTeacherActionType.get_teachers:
      return Object.assign({}, state, {
        teachers: action.teachers
      })
    case OnlineTeacherActionType.set_recording_status:
      const ls = resetRecordingList(state.recordingIds, action.tId, action.isRecording)
      return Object.assign({}, state, {
        recordingIds: ls
      })
    default:
      return state
  }
}
const resetRecordingList = (idArr, id, isRecoding) => {
  const arr = idArr.concat([])
  const isExist = idArr.indexOf(id) >= 0
  if (isExist && !isRecoding) {
    const index = idArr.indexOf(id)
    arr.splice(index, 1)
  }
  if (!isExist && isRecoding) {
    arr.push(id)
  }
  return arr
}
OnlineTeacherState._default_state = online_state
export default OnlineTeacherState
